
<template>
    <div class="spanControl-list" style="width: 100%;margin-left: 0!important;">
        <el-card class="box-card card-head" style="margin: 0px; width: 100%; min-height: 99%">
            <div slot="header" class="clearfix">
                <span>物流单管理</span>
            </div>
            <div class="alert-container clearfix">
                <el-alert  v-for="alert in alerts.successes"  :key="alert.title"
                           v-bind:title="alert.title"
                           type="success"
                           show-icon>
                </el-alert>
                <el-alert  v-for="alert in alerts.infos"  :key="alert.title"
                           v-bind:title="alert.title"
                           type="info"
                           show-icon >
                </el-alert>
                <el-alert  v-for="alert in alerts.warnings"  :key="alert.title"
                           v-bind:title="alert.title"
                           type="warning"
                           show-icon >
                </el-alert>
                <el-alert  v-for="alert in alerts.errors"  :key="alert.title"
                           v-bind:title="alert.title"
                           type="error"
                           show-icon >
                </el-alert>
            </div>
            <div class="text item">
                <el-form ref="logisticsForm" :model="logistics" label-width="150px" :rules="rules">
                                    <!--<el-col :span="11">-->
                                        <!--<el-form-item label="名称" prop="name">-->
                                            <!--<file-tip content="名称"></file-tip>-->
                                            <!--<el-input type="input" v-model="logistics.name"-->
                                                      <!--placeholder="名称" clearable autosize-->
                                                      <!--resize ="both" tabindex=1-->
                                                              <!--maxlength=255-->
                                            <!--&gt;</el-input>-->
                                    <!--</el-form-item>-->
                                    <!--</el-col>-->
                                    <el-col :span="11" v-if="edit">
                                        <el-form-item label="物流单号" prop="logisticsNumber">
                                            <file-tip content="物流单号"></file-tip>
                                            <el-input type="input" v-model="logistics.logisticsNumber"
                                                      placeholder="物流单号" clearable autosize
                                                      resize ="both" tabindex=3
                                                      maxlength=20
                                                      disabled="disabled"
                                            ></el-input>
                                    </el-form-item>
                                    </el-col>
                                    <el-col :span="11" v-if="edit">
                                        <el-form-item label="订单编号" prop="orderNumber">
                                            <file-tip content="订单编号"></file-tip>
                                            <el-input type="input" v-model="logistics.orderNumber"
                                                      placeholder="订单编号" clearable autosize
                                                      resize ="both" tabindex=4
                                                      maxlength=20
                                                      disabled="disabled"
                                            ></el-input>
                                    </el-form-item>
                                    </el-col>

                                <!--<el-col :span="11">-->
                                    <!--<el-form-item label="订单" prop="orderName">-->
                                        <!--<el-autocomplete-->
                                                <!--class="inline-input"-->
                                                <!--value-key="name"-->
                                                <!--v-model="logistics.orderName"-->
                                                <!--:fetch-suggestions="searchOrderName "-->
                                                <!--placeholder="订单"-->
                                                <!--@select="handleSelectOrderName"-->
                                                <!--clearable autosize-->
                                                <!--resize ="both" tabindex="5"-->
                                        <!--&gt;</el-autocomplete>-->
                                    <!--</el-form-item>-->
                                <!--</el-col>-->

                                <el-col :span="11">
                                    <el-form-item label="原金额" prop="payFor">
                                        <el-input type="number" step="0.01" v-model="logistics.payFor"
                                                  placeholder="原金额" clearable autosize
                                                  resize ="both" tabindex=6
                                                          maxlength=255
                                        ></el-input>
                                    </el-form-item>
                                </el-col>

                                <el-col :span="11">
                                    <el-form-item label="补贴金额" prop="subsidies">
                                        <el-input type="number" step="0.01" v-model="logistics.subsidies"
                                                  placeholder="补贴金额" clearable autosize
                                                  resize ="both" tabindex=7
                                                          maxlength=255
                                        ></el-input>
                                    </el-form-item>
                                </el-col>

                                <el-col :span="11">
                                    <el-form-item label="最终金额" prop="needPay">
                                        <el-input type="number" step="0.01" v-model="logistics.needPay"
                                                  placeholder="最终金额" clearable autosize
                                                  resize ="both" tabindex=8
                                                          maxlength=255
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="11">
                                    <el-form-item label="支付状态" prop="payStatus">
                                        <el-autocomplete
                                                class="inline-input"
                                                value-key="name"
                                                v-model="logistics.payStatus"
                                                :fetch-suggestions="searchPayStatus "
                                                placeholder="支付状态"
                                                clearable autosize
                                                resize ="both" tabindex="9"
                                        ></el-autocomplete>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="11">
                                    <el-form-item label="支付人" prop="payer">
                                        <el-autocomplete
                                                class="inline-input"
                                                value-key="name"
                                                v-model="logistics.payer"
                                                :fetch-suggestions="searchPayer "
                                                placeholder="支付人"
                                                clearable autosize
                                                resize ="both" tabindex="10"
                                        ></el-autocomplete>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="11">
                                    <el-form-item label="支付时间" prop="payTimeOne">
                                        <el-date-picker clearable
                                                v-model="logistics.payTimeOne"
                                                align="right"
                                                type="date"
                                                placeholder="支付时间"
                                                :picker-options="pickerOptionsPayTimeOne">
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="11">
                                    <el-form-item label="是否付清" prop="payAll">
                                        <el-autocomplete
                                                class="inline-input"
                                                value-key="name"
                                                v-model="logistics.payAll"
                                                :fetch-suggestions="searchPayAll "
                                                placeholder="是否付清"
                                                clearable autosize
                                                resize ="both" tabindex="12"
                                        ></el-autocomplete>
                                    </el-form-item>
                                </el-col>
                                    <el-col :span="11">
                                        <el-form-item label="货款收缴方式" prop="payMethod">
                                            <file-tip content="货款收缴方式"></file-tip>
                                            <el-input type="input" v-model="logistics.payMethod"
                                                      placeholder="货款收缴方式" clearable autosize
                                                      resize ="both" tabindex=13
                                                              maxlength=20
                                            ></el-input>
                                    </el-form-item>
                                    </el-col>
                                <el-col :span="11">
                                    <el-form-item label="货款收缴时间" prop="payTime">
                                        <el-date-picker clearable
                                                v-model="logistics.payTime"
                                                align="right"
                                                type="date"
                                                placeholder="货款收缴时间"
                                                :picker-options="pickerOptionsPayTime">
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="11">
                                    <el-form-item label="物流路线" prop="routeName">
                                        <el-autocomplete
                                                class="inline-input"
                                                value-key="name"
                                                v-model="logistics.routeName"
                                                :fetch-suggestions="searchRouteName "
                                                placeholder="物流路线"
                                                @select="handleSelectRouteName"
                                                clearable autosize
                                                resize ="both" tabindex="15"
                                        ></el-autocomplete>
                                    </el-form-item>
                                </el-col>

                                <el-col :span="11">
                                    <el-form-item label="发货时间" prop="deliveryTime">
                                        <el-date-picker clearable
                                                v-model="logistics.deliveryTime"
                                                align="right"
                                                type="date"
                                                placeholder="发货时间"
                                                :picker-options="pickerOptionsDeliveryTime">
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                                    <el-col :span="11">
                                        <el-form-item label="发货地址" prop="deliveryAddress">
                                            <file-tip content="发货地址"></file-tip>
                                            <el-input type="input" v-model="logistics.deliveryAddress"
                                                      placeholder="发货地址" clearable autosize
                                                      resize ="both" tabindex=17
                                                              maxlength=100
                                            ></el-input>
                                    </el-form-item>
                                    </el-col>
                                    <el-col :span="11">
                                        <el-form-item label="收货地址" prop="receiptAddress">
                                            <file-tip content="收货地址"></file-tip>
                                            <el-input type="input" v-model="logistics.receiptAddress"
                                                      placeholder="收货地址" clearable autosize
                                                      resize ="both" tabindex=18
                                                              maxlength=100
                                            ></el-input>
                                    </el-form-item>
                                    </el-col>

                                <el-col :span="11">
                                    <el-form-item label="商家" prop="businessName">
                                        <el-autocomplete
                                                class="inline-input"
                                                value-key="name"
                                                v-model="logistics.businessName"
                                                :fetch-suggestions="searchBusinessName "
                                                placeholder="商家"
                                                @select="handleSelectBusinessName"
                                                clearable autosize
                                                resize ="both" tabindex="19"
                                        ></el-autocomplete>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="11">
                                    <el-form-item label="用户" prop="employeeName">
                                        <el-autocomplete
                                                class="inline-input"
                                                value-key="name"
                                                v-model="logistics.employeeName"
                                                :fetch-suggestions="searchEmployeeName "
                                                placeholder="用户"
                                                @select="handleSelectEmployeeName"
                                                clearable autosize
                                                resize ="both" tabindex="20"
                                        ></el-autocomplete>
                                    </el-form-item>
                                </el-col>

                                    <el-col :span="11">
                                        <el-form-item label="当前节点" prop="currentNode">
                                            <file-tip content="当前节点"></file-tip>
                                            <el-input type="input" v-model="logistics.currentNode"
                                                      placeholder="当前节点" clearable autosize
                                                      resize ="both" tabindex=21
                                                              maxlength=50
                                            ></el-input>
                                    </el-form-item>
                                    </el-col>
                                <el-col :span="11">
                                    <el-form-item label="当前状态" prop="currentStatus">
                                        <el-autocomplete
                                                class="inline-input"
                                                value-key="name"
                                                v-model="logistics.currentStatus"
                                                :fetch-suggestions="searchCurrentStatus "
                                                placeholder="当前状态"
                                                clearable autosize
                                                resize ="both" tabindex="22"
                                        ></el-autocomplete>
                                    </el-form-item>
                                </el-col>
                                <!--<el-col :span="22">-->
                                    <!--<el-form-item label="备注" prop="remark">-->
                                        <!--<file-tip content="备注"></file-tip>-->
                                            <!--<el-input type="textarea" v-model="logistics.remark"-->
                                                      <!--placeholder="备注" clearable autosize-->
                                                      <!--resize ="both" tabindex=10000-->
                                                              <!--maxlength=255-->
                                            <!--&gt;</el-input>-->
                                    <!--</el-form-item>-->
                                <!--</el-col>-->
                    <el-col :span="11">
                        <el-form-item>
                            <el-button type="primary" @click="submitLogistics()"    :loading="isSubmiting" v-permission:simple_logistics_Logistics_Edit >提交</el-button>
                        </el-form-item>
                    </el-col>
                </el-form>
            </div>
            <div class="text item clearfix">
                <el-alert v-for="remark in alerts.remarks"  :key="remark.title"
                          v-bind:title="remark.title"
                          type="info"
                          v-bind:description="remark.content">
                </el-alert>
            </div>
        </el-card>
    </div>
</template>

<script>








import {OrderService} from '../../simple/order/OrderService'
import {RouteService} from '../../simple/logistics/RouteService'
import {BusinessService} from '../../simple/businessRegistration/BusinessService'
import {EmployeeService} from '../../simple/organization/EmployeeService'
import {LogisticsService} from './LogisticsService'
import {d4utils} from '../../../tools/d4utils'
    import fileTip from '@/components/tip/fileTip'
export default {
    components: {
        fileTip
    },
    data() {
        var validateIntRange = d4utils.validateFloatRange;
        var validateFloatRange = d4utils.validateFloatRange;
        var validateString = d4utils.validateString;

        return {
            rules: {
                name: [
                    {required:  false , message: '请输入名称', trigger: 'blur'},
                    { validator:validateString(0,1000,/^.*$/,"输入的数据不正确，请检查"), trigger: 'blur' },
                    ],
                logisticsNumber: [
                    {required:  true , message: '请输入物流单号', trigger: 'blur'},
                    { validator:validateString(0,1000,/^.*$/,"输入的数据不正确，请检查"), trigger: 'blur' },
                    ],
                orderNumber: [
                    {required:  true , message: '请输入订单编号', trigger: 'blur'},
                    { validator:validateString(0,1000,/^.*$/,"输入的数据不正确，请检查"), trigger: 'blur' },
                    ],
                orderId: [
                    {required:  false , message: '请输入订单', trigger: 'blur'},
                    ],
                orderName: [
                    {required:  false , message: '请输入订单', trigger: 'blur'},
                    ],
                payFor: [
                    {required:  true , message: '请输入原金额', trigger: 'blur'},
                    { validator: validateFloatRange(-9223372036854775808,9223372036854775807), trigger: 'blur' },
                    ],
                subsidies: [
                    {required:  true , message: '请输入补贴金额', trigger: 'blur'},
                    { validator: validateFloatRange(-9223372036854775808,9223372036854775807), trigger: 'blur' },
                    ],
                needPay: [
                    {required:  true , message: '请输入最终金额', trigger: 'blur'},
                    { validator: validateFloatRange(-9223372036854775808,9223372036854775807), trigger: 'blur' },
                    ],
                payStatus: [
                    {required:  true , message: '请输入支付状态', trigger: 'blur'},
                    ],
                payer: [
                    {required:  true , message: '请输入支付人', trigger: 'blur'},
                    ],
                payTimeOne: [
                    { required:  true , message: '请输入支付时间', trigger: 'change'},
                    ],
                payAll: [
                    {required:  true , message: '请输入是否付清', trigger: 'blur'},
                    ],
                payMethod: [
                    {required:  true , message: '请输入货款收缴方式', trigger: 'blur'},
                    { validator:validateString(0,1000,/^.*$/,"输入的数据不正确，请检查"), trigger: 'blur' },
                    ],
                payTime: [
                    { required:  true , message: '请输入货款收缴时间', trigger: 'change'},
                    ],
                routeName: [
                    {required:  false , message: '请输入物流路线', trigger: 'blur'},
                    ],
                routeId: [
                    {required:  false , message: '请输入物流路线', trigger: 'blur'},
                    ],
                deliveryTime: [
                    { required:  false , message: '请输入发货时间', trigger: 'change'},
                    ],
                deliveryAddress: [
                    {required:  false , message: '请输入发货地址', trigger: 'blur'},
                    { validator:validateString(0,1000,/^.*$/,"输入的数据不正确，请检查"), trigger: 'blur' },
                    ],
                receiptAddress: [
                    {required:  false , message: '请输入收货地址', trigger: 'blur'},
                    { validator:validateString(0,1000,/^.*$/,"输入的数据不正确，请检查"), trigger: 'blur' },
                    ],
                businessId: [
                    {required:  false , message: '请输入商家', trigger: 'blur'},
                    ],
                businessName: [
                    {required:  false , message: '请输入商家', trigger: 'blur'},
                    ],
                employeeName: [
                    {required:  false , message: '请输入用户', trigger: 'blur'},
                    ],
                employeeId: [
                    {required:  false , message: '请输入用户', trigger: 'blur'},
                    ],
                currentNode: [
                    {required:  false , message: '请输入当前节点', trigger: 'blur'},
                    { validator:validateString(0,1000,/^.*$/,"输入的数据不正确，请检查"), trigger: 'blur' },
                    ],
                currentStatus: [
                    {required:  false , message: '请输入当前状态', trigger: 'blur'},
                    ],
                remark: [
                    {required:  false , message: '请输入备注', trigger: 'blur'},
                    { validator:validateString(0,1000,/^.*$/,"输入的数据不正确，请检查"), trigger: 'blur' },
                    ],
           },
            isSubmiting: false,
            logistics:{},
            edit: null,
            logisticsId:null,
            pickerOptionsPayTimeOne: {
                disabledDate(time) {
                    //TODO: 请在此判断可以输入的日期范围,
                    //return time.getTime() > Date.now();
                    return false;
                },
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                }, {
                    text: '一周前',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', date);
                    }
                }]
            },
            pickerOptionsPayTime: {
                disabledDate(time) {
                    //TODO: 请在此判断可以输入的日期范围,
                    //return time.getTime() > Date.now();
                    return false;
                },
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                }, {
                    text: '一周前',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', date);
                    }
                }]
            },
            pickerOptionsDeliveryTime: {
                disabledDate(time) {
                    //TODO: 请在此判断可以输入的日期范围,
                    //return time.getTime() > Date.now();
                    return false;
                },
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                }, {
                    text: '一周前',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', date);
                    }
                }]
            },
            pickerOptionsCreateDatetime: {
                disabledDate(time) {
                    //TODO: 请在此判断可以输入的日期范围,
                    //return time.getTime() > Date.now();
                    return false;
                },
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                }, {
                    text: '一周前',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', date);
                    }
                }]
            },
            pickerOptionsUpdateDatetime: {
                disabledDate(time) {
                    //TODO: 请在此判断可以输入的日期范围,
                    //return time.getTime() > Date.now();
                    return false;
                },
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                }, {
                    text: '一周前',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', date);
                    }
                }]
            },
        alerts:{ remarks:[{title:"功能说明",content:"TODO: 请在这里加上功能说明"},],
                successes:[], //TODO:[{title:'消息内容'},]
                infos:[],
                warnings:[],
                errors:[]},
        }
    },

    methods: {
        addAlert(message,title,type){
            //type 可选的值为:remarks,successes,infos,warnings,errors
            type = type? type:"errors";
            type = this.alerts[type]?type:"errors";
            title = title?title:message;
            this.alerts[type].unshift({title:title,content:message});
        },
        removeAlert(title,type){
            //type 可选的值为:remarks,successes,infos,warnings,errors
            type = type? type:"errors";
            type = this.alerts[type]?type:"errors";
            for (var i = this.alerts[type].length-1; i>=0 ; i--) {
                delete this.alerts[type][i]
            }
        },
        submitLogistics() {
            var refs = this.$refs;
            refs['logisticsForm'].validate(valid => {
            if (valid) {
            if(this.logistics.eid)//编辑物流单
            {
            this.updateLogistics();
            }
            else//保存物流单
            {
            this.saveLogistics();
            }
            } else {
            return false
            }
            })
        },
        saveLogistics()//保存物流单
        {
            this.isSubmiting = true;
            this.buttonRequestProgressStart("正在保存,请稍后...");
            LogisticsService.saveLogistics(this.logistics).then((resp) => {
                this.buttonRequestProgressClose();
                this.isSubmiting = false;
                var router = this.$router;
                router.push({path: '/simple/logistics/logistics'})
        }).catch((error) => {
            this.buttonRequestProgressClose();
            //error的data属性是后台传入的数据,data的extendedData存有后台传入的数据
            this.isSubmiting = false;

            this.addAlert({title:error.data.message})
            this.$message({
                type: 'error',
                message: '保存出错,原因是：'+error.data.message
            })
        })
        },
        updateLogistics()//编辑物流单
        {
            this.isSubmiting = true;
            this.buttonRequestProgressStart("正在更新,请稍后...");
            LogisticsService.updateLogistics(this.logistics).then((resp) => {
                this.buttonRequestProgressClose();
                this.isSubmiting = false;
                var router = this.$router;
                router.push({path: '/simple/logistics/logistics'})
        }).catch((error) => {
            this.buttonRequestProgressClose();
            //error的data属性是后台传入的数据,data的extendedData存有后台传入的数据
            this.isSubmiting = false;
            this.addAlert({title:error.data.message})
            this.$message({
                type: 'error',
                message: '保存出错,原因是：'+error.data.message
            })

        })
        },
        findLogisticsForEdit(logisticsId)//查找物流单
        {
            LogisticsService.findLogisticsForEdit(logisticsId).then((resp) => {
                this.prepareForEdit(resp.data);
        }).catch((error) => {
            this.$message({
            type: 'error',
            message: '查询物流单出错'
        })
        })
        },
        createLogistics()//创建新的物流单
        {
            LogisticsService.createLogistics().then((resp) => {
                this.prepareForEdit(resp.data);
        }).catch((error) => {
            this.$message({
            type: 'error',
            message: '创建新的物流单出错'
        })
        })
        },
        prepareForEdit(logisticsEditDto)
        {
            this.logistics = logisticsEditDto.logistics;

            this.payStatusCodeTables = logisticsEditDto.payStatusCodeTables;
            this.payerCodeTables = logisticsEditDto.payerCodeTables;
            this.payAllCodeTables = logisticsEditDto.payAllCodeTables;
            this.currentStatusCodeTables = logisticsEditDto.currentStatusCodeTables;
            this.orderOrders = logisticsEditDto.orderOrders
            this.routeRoutes = logisticsEditDto.routeRoutes
            this.businessBusinesss = logisticsEditDto.businessBusinesss
            this.employeeEmployees = logisticsEditDto.employeeEmployees
        },
        searchPayStatus(queryString, cb) {
            var payStatusCodeTables = this.payStatusCodeTables;
            var results = queryString ? payStatusCodeTables.filter(this.createFilterPayStatus(queryString)) : payStatusCodeTables;
            cb(results);
        },
        createFilterPayStatus(queryString) {
            return (PayStatus) => {
                return (PayStatus.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
            };
        },
        searchPayer(queryString, cb) {
            var payerCodeTables = this.payerCodeTables;
            var results = queryString ? payerCodeTables.filter(this.createFilterPayer(queryString)) : payerCodeTables;
            cb(results);
        },
        createFilterPayer(queryString) {
            return (PayerType) => {
                return (PayerType.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
            };
        },
        searchPayAll(queryString, cb) {
            var payAllCodeTables = this.payAllCodeTables;
            var results = queryString ? payAllCodeTables.filter(this.createFilterPayAll(queryString)) : payAllCodeTables;
            cb(results);
        },
        createFilterPayAll(queryString) {
            return (PayAllType) => {
                return (PayAllType.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
            };
        },
        searchCurrentStatus(queryString, cb) {
            var currentStatusCodeTables = this.currentStatusCodeTables;
            var results = queryString ? currentStatusCodeTables.filter(this.createFilterCurrentStatus(queryString)) : currentStatusCodeTables;
            cb(results);
        },
        createFilterCurrentStatus(queryString) {
            return (CurrentStatus) => {
                return (CurrentStatus.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
            };
        },


        searchOrderName(queryString, cb) {
            var orderOrders = this.orderOrders;

            //如果不为空，说明在加载页面的时候已经加载了所有的外键数据，否则表示没加载，则根据输入的信息从后台加载
            if(orderOrders)
            {
                var results = queryString ? orderOrders.filter(this.createFilterOrderName(queryString)) : orderOrders;
                cb(results);
            }
            else
            {
                var results = d4utils.getObjectCached("findOrdersWithIdNameByName_"+queryString);
                if(results)
                {
                    cb(results);
                }
                else
                {
                    var cb1 = cb;
                    OrderService.findOrdersWithIdNameByName(queryString).then((resp) => {
                    if (resp.data)
                    {
                        var results = resp.data;
                        d4utils.cacheObject("findOrdersWithIdNameByName_"+queryString);
                        cb1(results)
                    }
                else
                    {
                        this.$message({
                            type: 'error',
                            message: '没有查询到引用数据'
                        });
                    }
                }).catch((error) => {
                    this.$message({
                    type: 'error',
                    message: '查询引用数据出错'
                })
                });
                }
            }
        },
            createFilterOrderName(queryString) {
                return (order) => {
                    return (order.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
                };
            },
            handleSelectOrderName(item){
                this.logistics.orderId = item.eid;
            },

        searchRouteName(queryString, cb) {
            var routeRoutes = this.routeRoutes;

            //如果不为空，说明在加载页面的时候已经加载了所有的外键数据，否则表示没加载，则根据输入的信息从后台加载
            if(routeRoutes)
            {
                var results = queryString ? routeRoutes.filter(this.createFilterRouteName(queryString)) : routeRoutes;
                cb(results);
            }
            else
            {
                var results = d4utils.getObjectCached("findRoutesWithIdNameByName_"+queryString);
                if(results)
                {
                    cb(results);
                }
                else
                {
                    var cb1 = cb;
                    RouteService.findRoutesWithIdNameByName(queryString).then((resp) => {
                    if (resp.data)
                    {
                        var results = resp.data;
                        d4utils.cacheObject("findRoutesWithIdNameByName_"+queryString);
                        cb1(results)
                    }
                else
                    {
                        this.$message({
                            type: 'error',
                            message: '没有查询到引用数据'
                        });
                    }
                }).catch((error) => {
                    this.$message({
                    type: 'error',
                    message: '查询引用数据出错'
                })
                });
                }
            }
        },
            createFilterRouteName(queryString) {
                return (route) => {
                    return (route.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
                };
            },
            handleSelectRouteName(item){
                this.logistics.routeId = item.eid;
            },

        searchBusinessName(queryString, cb) {
            var businessBusinesss = this.businessBusinesss;

            //如果不为空，说明在加载页面的时候已经加载了所有的外键数据，否则表示没加载，则根据输入的信息从后台加载
            if(businessBusinesss)
            {
                var results = queryString ? businessBusinesss.filter(this.createFilterBusinessName(queryString)) : businessBusinesss;
                cb(results);
            }
            else
            {
                var results = d4utils.getObjectCached("findBusinesssWithIdNameByName_"+queryString);
                if(results)
                {
                    cb(results);
                }
                else
                {
                    var cb1 = cb;
                    BusinessService.findBusinesssWithIdNameByName(queryString).then((resp) => {
                    if (resp.data)
                    {
                        var results = resp.data;
                        d4utils.cacheObject("findBusinesssWithIdNameByName_"+queryString);
                        cb1(results)
                    }
                else
                    {
                        this.$message({
                            type: 'error',
                            message: '没有查询到引用数据'
                        });
                    }
                }).catch((error) => {
                    this.$message({
                    type: 'error',
                    message: '查询引用数据出错'
                })
                });
                }
            }
        },
            createFilterBusinessName(queryString) {
                return (business) => {
                    return (business.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
                };
            },
            handleSelectBusinessName(item){
                this.logistics.businessId = item.eid;
            },

        searchEmployeeName(queryString, cb) {
            var employeeEmployees = this.employeeEmployees;

            //如果不为空，说明在加载页面的时候已经加载了所有的外键数据，否则表示没加载，则根据输入的信息从后台加载
            if(employeeEmployees)
            {
                var results = queryString ? employeeEmployees.filter(this.createFilterEmployeeName(queryString)) : employeeEmployees;
                cb(results);
            }
            else
            {
                var results = d4utils.getObjectCached("findEmployeesWithIdNameByName_"+queryString);
                if(results)
                {
                    cb(results);
                }
                else
                {
                    var cb1 = cb;
                    EmployeeService.findEmployeesWithIdNameByName(queryString).then((resp) => {
                    if (resp.data)
                    {
                        var results = resp.data;
                        d4utils.cacheObject("findEmployeesWithIdNameByName_"+queryString);
                        cb1(results)
                    }
                else
                    {
                        this.$message({
                            type: 'error',
                            message: '没有查询到引用数据'
                        });
                    }
                }).catch((error) => {
                    this.$message({
                    type: 'error',
                    message: '查询引用数据出错'
                })
                });
                }
            }
        },
            createFilterEmployeeName(queryString) {
                return (employee) => {
                    return (employee.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
                };
            },
            handleSelectEmployeeName(item){
                this.logistics.employeeId = item.eid;
            },
    },
    created() {
        this.logisticsId = this.$route.params.logisticsId;
        if(this.logisticsId)//编辑
        {
            this.edit = true;
            this.findLogisticsForEdit(this.logisticsId);
        }
        else//新增
        {
            this.edit = false;
            this.createLogistics();
        }
    },
}
</script>
<style scoped lang="scss">

</style>
